<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/admin/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>评价管理</el-breadcrumb-item>
      <el-breadcrumb-item>评价图表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
      <el-page-header @back="goBack" content="选择商家">
      </el-page-header>
      <div id="main"></div>
    </el-card>
  </div>
</template>

<script>
import echarts from 'echarts'

export default {
  name: 'ShowReport2',
  data () {
    return {
      option: {
        title: {
          text: '菜品评价占比'
        },
        series: [
          {
            name: '评价占比',
            type: 'pie',
            roseType: 'angle',
            radius: '55%',
            data: []
          }
        ]
      }
    }
  },
  // 页面上的元素都渲染完成后，调用该函数
  async mounted () {
    const myChart = echarts.init(document.getElementById('main'))
    const rid = { rid: this.$route.params.rid }
    const { data: res } = await this.$axios.get('/admin/restaurant/queryByID', { params: rid })
    if (res.status !== 2000) {
      return this.$message.error('获取数据失败')
    }
    const dataList = []
    res.data.foods.forEach(function (item) {
      dataList.push({ value: item.count, name: item.fname })
    })
    this.option.series[0].data = dataList
    myChart.setOption(this.option)
  },
  methods: {
    goBack () {
      this.$router.go(-1)
    }
  }
}
</script>

<style scoped>
#main {
  margin-top: 30px;
  width: 1300px;
  height: 400px;
}
</style>
